<template>
  <el-button-group>
    <el-button 
      v-for="item in actionGroup"
      :key="item.id"
      @click="action(item)" 
      type="primary"
    >
      {{item.modulename}}
    </el-button>
  </el-button-group>
</template>
<script>
export default {
  name:'EditBtn',
  props:['selected'],
  created(){    
    const currentPath=this.$route.path
    for(let i in this.$store.state.moduleData){
      if(this.$store.state.moduleData[i].modulepath==currentPath){
        this.actionGroup=this.$store.state.moduleData[i]['children']
        break
      }
    }
  },
  data(){
    return {
      actionGroup:[]
    }
  },
  methods:{
    action(action){
      if(action.actiontype==0){
        let id=this.$store.state.adminData.id
        this.$router.push({
          path:action.modulepath,
          query:{id}
        })
      }else if(action.actiontype==1){
        if(this.selected.length==1){
          this.$router.push({
            path:action.modulepath,
            query:{id:this.selected}
          })
        }else if(this.selected.length<1){
          this.message('请至少选择一条要修改的数据','warning')
        }else if(this.selected.length>1){
          this.message('修改操作只能选择一条数据','warning')
        }
      }else{
        if(this.selected.length<1){
          this.message('请至少选择一条要删除的数据','warning')
        }else{  
          this.$router.push({
            path:action.modulepath,
            query:{id:this.selected}
          })
        }        
      }
    },
    handleSlectionChange(select){
      this.selected=select
    },
    message(msg,type){
      this.$message({
        message:msg,
        type
      })
    }
  }
}
</script>
<style scoped>

</style>
